package com.wthink.hzgj.menu

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.wthink.hzgj.data.Result
import com.wthink.hzgj.data.domain.CheckinType
import com.wthink.hzgj.data.domain.SettingKey
import com.wthink.hzgj.data.repository.SettingWithCacheRepository
import com.wthink.hzgj.service.DevService

class LoginModel : ViewModel(){

    val loginAdmin = MutableLiveData("")
    val loginPwd = MutableLiveData("")

    val settingRepository = SettingWithCacheRepository

    suspend fun action(): String? {
        val loginAdmin = loginAdmin.value!!
        val loginPwd = loginPwd.value!!

        if (loginAdmin.isEmpty() || loginPwd.isEmpty()) {
            return "请输入账号密码"
        }

        val ret = DevService.checkin(
            settingRepository.findSetting(SettingKey.LINE)!!,
            "",
            CheckinType.QD
        )
        if (ret is Result.Success) {

            return null
        } else if (ret is Result.Error) {
            return ret.exception.message
        } else {
            return null
        }
    }

}